<template>
  <div class="commentItem" v-if="parent">
    <div class="head">
      <!-- <img :src="parent.user.head_img" alt /> -->
      <div>
        <p>{{ parent.user.nickname }}</p>
        <span>{{ parent.create_date }}</span>
      </div>
      <span>回复</span>
    </div>

    <!-- 递归运用 -->
    <itCommentItem :parent="parent.parent"></itCommentItem>

    <div class="text">{{ parent.content }}</div>
  </div>
</template>

<script>
// 导入moment时间格式框架
import moment from "moment";

import myaxios from "@/utils/myAxios.js";

export default {
  // 递归自己, 不能用import引入  通过下面方式引入
  name: "itCommentItem",

  // 组件传值
  props: {
    parent: {
      type: Object,
    },
  },
  //   钩子
  mounted() {
    console.log("不错");
    //  console.log(this.parent);
    if (this.parent) {
      this.parent.create_date = moment(this.parent.create_date).fromNow();
      this.parent.user.head_img =
        myaxios.defaults.baseURL + this.parent.user.head_img;
    }
  },
  //   侦听器
  watch: {},
};
</script>

// 样式：
<style lang="less" scoped>
.commentItem {
  padding: 4px;
  border: 1px solid #ccc;
  margin-top: 4px;
  margin-bottom: 4px;
  .head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    > img {
      width: 50/360 * 100vw;
      height: 50/360 * 100vw;
      display: block;
      border-radius: 50%;
    }
    > div {
      flex: 1;
      display: flex;
      flex-direction: column;
      margin-left: 10px;
      > span {
        font-size: 12px;
        color: #999;
        line-height: 25px;
      }
    }
    > span {
      color: #999;
      font-size: 13px;
    }
  }
  .text {
    font-size: 14px;
    color: #333;
    padding: 20px 0 10px 0;
  }
}
</style>